package cn.itcast.service.system.impl;

import cn.itcast.dao.system.ModuleDao;
import cn.itcast.dao.system.RoleDao;
import cn.itcast.domain.system.Module;
import cn.itcast.domain.system.Role;
import cn.itcast.service.system.RoleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    @Autowired
    private ModuleDao moduleDao;

    @Override
    public Role findById(String id) {
        Role role = roleDao.findById(id);
        return role;
    }

    @Override
    public List<Role> findAll(String companyId) {
        List<Role> roles = roleDao.findAll(companyId);
        return roles;
    }

    @Override
    public void delete(String id) {
        roleDao.delete(id);
    }

    @Override
    public void save(Role role) {
        role.setId(UUID.randomUUID().toString());
        roleDao.save(role);
    }

    @Override
    public void update(Role role) {
        roleDao.update(role);
    }

    @Override
    public PageInfo<Role> findByPage(String companyId, int pageNum, int pageSize) {
        Page<Role> page = PageHelper.startPage(pageNum, pageSize);
        List<Role> list = roleDao.findAll(companyId);
        PageInfo<Role> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Role> findRoleByUserId(String id) {
        List<Role> roleList = roleDao.findRoleByUserId(id);
        return roleList;
    }

    @Override
    public void cleanRoleModuleById(String id) {
        roleDao.cleanRoleModuleById(id);
    }

    @Override
    public void updateRoleModule(String id, String moduleId) {
        roleDao.updateRoleModule(id,moduleId);
    }

}
